// 绝对路径
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { DefinePlugin } = require('webpack')

module.exports = {
  mode: "development",
  entry: "./src/react_index.jsx",
  // 
  // devtool: "source-map",
  // devtool: false,
  // devtool: "eval-source-map",
  // devtool: "inline-source-map",
  // devtool: "cheap-source-map",
  // devtool: "cheap-module-source-map",
  // devtool: "hidden-source-map",
  devtool: "nosources-source-map",
  output: {
    filename: "js/bundle.js",
    // 绝对路径，拼接相对路径
    path: path.resolve(__dirname, "./build"),
    // assetModuleFilename: "img/[name].[hash:6][ext]"
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          // options: {
          //   // 整合所有(大部分)的插件
          //   presets: [
          //     // "@babel/preset-env", 
          //     "preset-env", "preset-react"
          //   ]
          // }
        }
      }
    ]   
  },
  plugins: [
    // 自动删除打包的文件
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      title: "yz webpack",
      template: "./index.html"
    }),
  ]
}